Inport the libraries and dataset
#install.packages("sf")
#install.packages("ggplot2")
#install.packages("tidyverse")
#install.packages("plotly")
setwd("~/Desktop/USRA/california fire")
library(sf)
library(ggplot2)
library(tidyverse)
library(plotly)
fire_data<-st_read("California_Historic_Fire_Perimeters.geojson")
## Reading layer `California_Historic_Fire_Perimeters' from data source
## `/Users/nancy/Desktop/USRA/california fire/California_Historic_Fire_Perimeters.geojson'
## using driver `GeoJSON'
## Simple feature collection with 22810 features and 19 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -13848330 ymin: 3833204 xmax: -12705610 ymax: 5255380
## Projected CRS: WGS 84 / Pseudo-Mercator
# full path to folder containing the files
shapefile_path <- "/Users/nancy/Desktop/USRA/california fire/tl_2023_us_state/tl_2023_us_state.shp"
# read california border map
stateshapes <- st_read(shapefile_path)
## Reading layer `tl_2023_us_state' from data source
## `/Users/nancy/Desktop/USRA/california fire/tl_2023_us_state/tl_2023_us_state.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 56 features and 15 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -179.2311 ymin: -14.60181 xmax: 179.8597 ymax: 71.43979
## Geodetic CRS: NAD83
CA_shape<-stateshapes %>% filter(NAME=="California")
Seperate the data into four parts depending on their decades.
fires_1990s<-fire_data %>% filter(DECADES=="1990-1999")
fires_2000s<-fire_data %>% filter(DECADES=="2000-2009")
fires_2010s<-fire_data %>% filter(DECADES=="2010-2019")
fires_2020s <- fire_data %>% filter(DECADES == "2020-January 2025")
Map of California fire in 2020s.
#Map of California fire in 2020s
ggplot()+
geom_sf(data = fires_2020s,fill = "darkorange", color = "darkred")+
geom_sf(data = CA_shape, fill = NA, color = "black", size = 1)+
ggtitle("Fire Extents: 2020s") +
theme_minimal()
Map in 2010-2019.
ggplot()+
geom_sf(data = fires_2010s,fill = "darkorange", color = "darkred")+
geom_sf(data = CA_shape, fill = NA, color = "black", size = 1)+
ggtitle("Fire Extents: 2010s") +
theme_minimal()
Map in 2000-2009.
ggplot()+
geom_sf(data = fires_2000s,fill = "darkorange", color = "darkred")+
geom_sf(data = CA_shape, fill = NA, color = "black", size = 1)+
ggtitle("Fire Extents: 2000s") +
theme_minimal()
Maps in 1990-1999.
ggplot()+
geom_sf(data = fires_1990s,fill = "darkorange", color = "darkred")+
geom_sf(data = CA_shape, fill = NA, color = "black", size = 1)+
ggtitle("Fire Extents: 1990s") +
theme_minimal()
area_summary_by_decades<-fire_data %>%
st_drop_geometry()%>%
filter(YEAR_>=1950) %>%
group_by(DECADES) %>%
summarise(average=mean(GIS_ACRES)) %>%
na.omit()
ggplot(data = area_summary_by_decades,aes(x = DECADES, y = average, group = 1))+
geom_bar(stat = "identity",fill = "lightgrey")+
geom_point(color = "blue")+
geom_line(color = "red")+
theme_minimal()+
theme(axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(hjust = 0.5))+
labs(title = "Decade average fire area")
# Fire area summary according to years.
area_summary_by_year<-fire_data %>%
st_drop_geometry()%>%
filter(YEAR_>=1950) %>%
group_by(YEAR_) %>%
summarise(average=mean(GIS_ACRES)) %>%
na.omit()
ggplot(data = area_summary_by_year,aes(x = YEAR_, y = average))+
geom_line(color = "blue")+
geom_point(color = "red")+
labs(title = "Averaged fire area by year")
# Analyze the fire by seasons
fire_data<-fire_data %>%
mutate(month = substr(ALARM_DATE,9,11))
#introduce month to dataset
fire_data<-fire_data %>%
mutate(season = case_when(
month %in% c("Dec", "Jan", "Feb") ~ "Winter",
month %in% c("Mar", "Apr", "May") ~ "Spring",
month %in% c("Jun", "Jul", "Aug") ~ "Summer",
month %in% c("Sep", "Oct", "Nov") ~ "Fall",
TRUE ~ NA_character_
))
data_summary_by_decade_season<-fire_data %>%
st_drop_geometry() %>%
filter(YEAR_>=1950) %>%
group_by(DECADES,season) %>%
summarise(count = n(),
average_area = mean(GIS_ACRES)) %>%
na.omit()
## `summarise()` has grouped output by 'DECADES'. You can override using the
## `.groups` argument.
view(data_summary_by_decade_season)
ggplot(data = data_summary_by_decade_season, aes(group = season, color = season)) +
geom_bar(aes(x = DECADES, y = count, fill = season),
stat = "identity", position = "stack")+
theme_minimal()+
theme(axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(hjust = 0.5))+
labs(title = "Decades fire amount based on seasons")
ggplot(data = data_summary_by_decade_season,aes(group = season, color = season))+
geom_line(aes(x = DECADES, y = average_area))+
theme_minimal()+
theme(axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(hjust = 0.5))+
labs(title = "Decades fire averaged area based on seasons")
data_summary_by_season<-fire_data %>%
st_drop_geometry() %>%
filter(YEAR_>=1950) %>%
group_by(season) %>%
summarise(count = n(),
average_area = mean(GIS_ACRES)) %>%
na.omit()
data_summary_by_season <- data_summary_by_season %>%
mutate(season = factor(season,
levels = c("Spring", "Summer", "Fall","Winter")))
Make a graph of the count and averaged fire area according to seasons.
plot_ly() %>%
add_bars(
x = data_summary_by_season$season,
y = data_summary_by_season$count,
name = "Count",
yaxis = "y1"
) %>%
add_lines(
x = data_summary_by_season$season,
y = data_summary_by_season$average_area,
name = "Average Area",
yaxis = "y2"
) %>%
layout(
yaxis = list(title = "Count"),
yaxis2 = list(title = "Average Area", overlaying = "y", side = "right"),
xaxis = list(title = "Season"),
title = "Counts & Average Area"
)